﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;

namespace Sistema_de_Taller.SDT_UI.Employee
{
    public partial class employee_default : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //Variable que vale uno cuando es una modificación y 0 cuando es un insert
        public static int modifica = 0;
        public static UInt32 EmployeeID = 0;

        protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem edititem = e.Item as GridEditableItem;
            EmployeeID = Convert.ToUInt32(edititem["Employee_ID"].Text);
            txtName.Text = edititem["Employee_Name"].Text.Trim();
            txtResidence.Text = edititem["Employee_Residence"].Text.Trim();
            txtPhone.Text = edititem["Employee_Phone"].Text.Trim();
            pnlAddEmployee.Visible = true;
            modifica = 1;
        }

        protected void btnAcept_Click(object sender, EventArgs e)
        {
            //Aca se corre la query que actualizaria los campos de la fila correspondiente
            Common_Files.Definitions.Employee Employee = new Common_Files.Definitions.Employee();

            Employee.Employee_Name = txtName.Text.Trim();
            Employee.Employee_Residence = txtResidence.Text.Trim();
            Employee.Employee_Phone = txtPhone.Text.Trim();
            Employee.Employee_ID = EmployeeID;

            SDT_DAL.Utilities.Employee_DAL consulta = new SDT_DAL.Utilities.Employee_DAL();

            if (modifica == 0) consulta.EmployeeInsert(Employee);
            else consulta.EmployeeUpdate(Employee);

            Response.Redirect("~/SDT_UI/Employee/EmployeeDefault.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/SDT_UI/Employee/EmployeeDefault.aspx");
        }

        protected void btnAddVehicle_Click(object sender, EventArgs e)
        {
            pnlAddEmployee.Visible = true;
            modifica = 0;
        }
    }
}